/*
 * Project name:
     EasyPIC Spiral
 * Author:
     Samuel.B.Atlan@gmail.com
 * Revision History:
     2010/04/11: initial release;
 * Description:
     Turns on/off LEDs with a spiral effect.
     Spiral is made of 6 segments (6 functions)
 * Test configuration:
     MCU:             PIC16F887
     Dev.Board:       EasyPIC6
     Oscillator:      MCU 4.00 MHz, Internal RC no Clock (RA6 & RA7 as I/O)
     Ext. Modules:    -
     Software:        mikroC PRO for PIC 3.2
 * Notes:
     - None.
*/

char counter;

void line_1() {
// turns on all LEDs on PORTA from RA0 to RA7
    for (counter = 0; counter < 8; counter++){
      PORTA |= 1 << counter;
      Delay_ms(100);
    }
}
void line_2() {
// turns on LEDs Rx7
     PORTB |= 1 << 7;
     Delay_ms(100);
     PORTC |= 1 << 7;
     Delay_ms(100);
     PORTD |= 1 << 7;
     Delay_ms(100);
}
void line_3() {
// turns on all LEDs on PORTD from RD6 to RD0
    for (counter = 7; counter > 0; counter--){
      PORTD |= 1 << (counter-1);
      Delay_ms(100);
    }
}
void line_4() {
// turns on LEDs Rx0
     PORTC |= 1 << 0;
     Delay_ms(100);
     PORTB |= 1 << 0;
     Delay_ms(100);
}
void line_5() {
// turns on all LEDs on PORTB from RB1 to RB6
    for (counter = 1; counter < 7; counter++){
      PORTB |= 1 << counter;
      Delay_ms(100);
    }
}
void line_6() {
// turns on all LEDs on PORTC from RC6 to RC1
    for (counter = 7; counter > 1; counter--){
      PORTC |= 1 << (counter-1);
      Delay_ms(100);
    }
}

void main() {
  ANSEL  = 0;                                    // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  TRISA = 0x00;                                  // set direction to be output
  TRISB = 0x00;                                  // set direction to be output
  TRISC = 0x00;                                  // set direction to be output
  TRISD = 0x00;                                  // set direction to be output

  while (1) {
// Clear PORTs
  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
  PORTD = 0x00;

// Make Spiral
    line_1();
    line_2();
    line_3();
    line_4();
    line_5();
    line_6();
  }
}
